﻿using UnityEngine;


namespace RStudio.UIFramwork
{
    /// <summary>
    /// 图形界面|管理面板
    /// </summary>
    public class UIController
    {
        /// <summary>
        /// UI模块中心
        /// </summary>
        public UIModuleCenter UICenter;

        public UIController()
        {
            UICenter = new UIModuleCenter();
        }


        /// <summary>
        /// 访问|页面（类型）
        /// </summary>
        public void Open<T>() where T : UIBase
        {
            UIEventArg uiEvent = new()
            {
                Type = typeof(T),
                UIEventType = UIEventType.Open,
            };

            UICenter.SendToQueue(uiEvent);
        }

        /// <summary>
        /// 关闭|页面（类型）
        /// </summary>
        public void Close<T>() where T : UIBase
        {
            UIEventArg uiEvent = new()
            {
                Type = typeof(T),
                UIEventType = UIEventType.Close,
            };

            UICenter.SendToQueue(uiEvent);
        }

        /// <summary>
        /// 关闭|页面（指定）
        /// </summary>
        /// <param name="uiBase"></param>
        public void Close(UIBase uiBase)
        {
            UIEventArg uiEvent = new()
            {
                Type = uiBase.GetType(),
                UIBase = uiBase,
                UIEventType = UIEventType.Close,
            };

            UICenter.SendToQueue(uiEvent);
        }


        /// <summary>
        /// 回退|页面
        /// </summary>
        public void Back()
        {
            UIEventArg uiEvent = new()
            {
                UIEventType = UIEventType.Back,
            };

            UICenter.SendToQueue(uiEvent);
        }
    }
}